package com.ruoyi.basedocument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedocument.domain.BomPlant;
import com.ruoyi.basedocument.service.IBomPlantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间Controller
 * 
 * @author ruoyi
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/bomcostestimation/basedocument/plant")
public class BomPlantController extends BaseController
{
    @Autowired
    private IBomPlantService bomPlantService;

    /**
     * 查询车间列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:plant:list')")
    @GetMapping("/list")
    public TableDataInfo list(BomPlant bomPlant)
    {
        startPage();
        List<BomPlant> list = bomPlantService.selectBomPlantList(bomPlant);
        return getDataTable(list);
    }

    /**
     * 导出车间列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:plant:export')")
    @Log(title = "车间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomPlant bomPlant)
    {
        List<BomPlant> list = bomPlantService.selectBomPlantList(bomPlant);
        ExcelUtil<BomPlant> util = new ExcelUtil<BomPlant>(BomPlant.class);
        util.exportExcel(response, list, "车间数据");
    }

    /**
     * 获取车间详细信息
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:plant:query')")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") String fid)
    {
        return success(bomPlantService.selectBomPlantByFid(fid));
    }

    /**
     * 新增车间
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:plant:add')")
    @Log(title = "车间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomPlant bomPlant)
    {
        return toAjax(bomPlantService.insertBomPlant(bomPlant));
    }

    /**
     * 修改车间
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:plant:edit')")
    @Log(title = "车间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BomPlant bomPlant)
    {
        return toAjax(bomPlantService.updateBomPlant(bomPlant));
    }

    /**
     * 删除车间
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:plant:remove')")
    @Log(title = "车间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable String[] fids)
    {
        return toAjax(bomPlantService.deleteBomPlantByFids(fids));
    }
}
